<?php
require_once ('../libraryfiles/config.php');
$variable = ((!empty($_GET['action'])) ? $_GET['action'] : '');
switch ($variable) {
    case 'byprovince':
        if ($_POST['id']) {
            $id = $_POST['id'];
            $table = Tblrefcode::tblname;
            $where = array(
                Tblrefcode::oject_id => $id,
                Tblrefcode::type => 'district_state',
            );
            /* select from table refcode for get parent id */
            $get_id = select($table, array(Tblrefcode::oject_id, Tblrefcode::value), $where);
            //$sql = mysql_query("select b.id,b.data from data_parent a,data b where b.id=a.did and parent='$id'");
            $table_district = Tblstate::tblname;
            $disctict = array();
            $i = 0;
            while ($row_id = mysql_fetch_array($get_id)) {
                $id_dist = $row_id[Tblrefcode::value];
                $where_id = array(
                    Tblstate::id => $id_dist
                );
                $get_distict = select($table_district, array(Tblstate::id, Tblstate::name, Tblstate::lat_long), $where_id);
                while ($row_district = mysql_fetch_array($get_distict)) {
                    $disctict[$i][Tblstate::id] = $row_district[Tblstate::id];
                    $disctict[$i][Tblstate::name] = $row_district[Tblstate::name];
                    $disctict[$i][Tblstate::lat_long] = $row_district[Tblstate::lat_long];
                }
                $i++;
            }
            ?>
            <option value=""><?php echo $lang['UR_DISTRICT']; ?></option>
            <?php foreach ($disctict as $value):
                ?>
                <option value="<?php echo $value[Tblstate::id]; ?>" data-gps="<?php echo $value[Tblstate::lat_long]; ?>"><?php echo $value[Tblstate::name]; ?></option>
                <?php
            endforeach;
        }

    case 'checkemail':
        if (!empty($_POST['id'])) {
            $where_user = array(
                Tbluser::email => $_POST['id']
            );
            $string = select(Tbluser::Tbluser, array(Tbluser::email), $where_user);
            if (dbNumRows($string)) {
                echo 1;
            } else {
                echo 0;
            }
        }
        break;
}